import java.io.*;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;

abstract class BankomatMethods {

    private static final String TRY_CONNECTION = "ready... try Connection to server\n";
    private static final String NO_CONNECTION = "NO CONNECTION TO SERVER. TRY LATER\n";
    private static final String INFO = "\nI N F O R M A T I O N\n";
    private static final String ENTER_MENU = "\nTo continue type      1\n\nFor information type  2\n\nTo exit enter         0 \n";

    protected String connectToServerAndProvideTransaction(Integer inputdata, String somecach, String readline) throws IOException {
        String str = null;
        String showData;
        System.out.println(TRY_CONNECTION);
        try {
            Socket socket = new Socket("localhost", 7001);
            OutputStream outputS = socket.getOutputStream();
            DataOutputStream outputData = new DataOutputStream(outputS);
            showData = new SimpleDateFormat("hh.mm.ss").format(new Date());
            outputData.writeUTF("[" + showData + "] <" + inputdata + "> # " + readline + "want " + somecach + "            ");

            InputStream inputS = socket.getInputStream();
            DataInputStream inputData = new DataInputStream(inputS);
            str = inputData.readUTF();
            System.out.print("\n" + str + "\n");
        } catch (Exception x) {
            clearUserScreen();
            System.out.println(NO_CONNECTION);
        } finally {
            return str;
        }
    }

    public void getInfo() {
        clearUserScreen();
        System.out.println(INFO);
    }

    public static void clearUserScreen() {
        for (int i = 0; i < 50; i++) {
            System.out.println("\n");
        }
    }

    public static void sayHello() {
        System.out.println(ENTER_MENU);
    }
}
